<?php
namespace Admin\Controller;
use Admin\Logic\GoodsLogic;
use Think\Cache\Driver\Redis;
class SystemController extends BaseController{
	
	/*
	 * 配置入口
	 */
	public function index()
	{
		/*配置列表*/
		if(empty($_GET['inc_type'])){
			$_GET['inc_type']="basic";
		}
		$group_list = array('basic'=>'基本设置','longhu'=>'排行榜','sms'=>'短信设置','shopping'=>'购物流程设置','shop_info'=>'系统设置','zhuanpan'=>'<span style="color:red">转盘活动</span>');// ,'distribut'=>'分销设置');
		$this->assign('group_list',$group_list);
		$inc_type =  I('get.inc_type','shop_info');
		$this->assign('inc_type',$inc_type);
		$this->initEditor(); // 编辑器
		$data = tpCache($inc_type);
		if($inc_type == 'full_reduction'){
		    $data['full'] = json_decode($data['full'],true);
		}
		$this->assign('config',$data);//当前配置项
		if($inc_type=='zhuanpan'){
			$lipin=M('zhuanpan')->select();
			$this->assign('zps',$lipin);
		}
		if($inc_type=='zhuanpan'){
			$lipin=M('zhuanpan')->select();
			$this->assign('zps',$lipin);
		}
		
        $this->assign('time',date('Y-m-d H:i:s',time()));
        C('TOKEN_ON',false);
		$this->display($inc_type);
	}
	public function line(){
	    $userline = M('users')->field('biaoshi_xian')->where('biaoshi_xian != "" and is_driver = 0')->group('biaoshi_xian')->select();
	    foreach ($userline as $k=>$v){
	        $line = M('line')->where(['title'=>$v['biaoshi_xian']])->find();
	        if(empty($line)){
	            $lineData = [];
	            $lineData['title'] = $v['biaoshi_xian'];
	            $lineData['addtime'] = time();
	            M('line')->add($lineData);
	        }
	    }
        $lineList = M('line')->select();
        foreach($lineList as $k=>$v){
            $lineList[$k]['images'] = 'https://'.$_SERVER['SERVER_NAME'].'/'.$v['images'];
        }
        $this->assign('line',$lineList);
        $this->display('');    
	}
		public  function addline(){  
	    $id = $_GET['id'] ? $_GET['id'] : 0; 
        if(IS_POST)
        {   
            if(empty(I('images'))){
                $this->error("请上传图片");       
            }
		    M('line')->where(['id'=>$id])->save(['images'=>I('images')]);
            $this->success("操作成功!!!",U('Admin/System/line'));               
            exit;
        }                    
       // 点击过来编辑时                 
             
       $navigation = M('line')->find($id);      
       $this->assign('navigation',$navigation);
       $this->display('');
    }
    /**
     * 线路关联酷点的门店id
     */
    public function xian_shop()
    {

        $keywords = I('keywords',false);
        $where = '';
        if($keywords){
            $where = " and biaoshi_xian like '%$keywords%'";
        }

        $xian = M('users')->field('biaoshi_xian')->where('biaoshi_xian != "" '.$where.' ')->group('biaoshi_xian')->order('biaoshi_xian asc')->select();
        foreach ($xian as $k=>$v){
            $xian[$k]['shopid'] = M('xian_shop')->where(['xian'=>$v['biaoshi_xian']])->getField('shopid');
        }
        $this->assign('list',$xian);
        $this->display();
    }
	
	//添加修改转盘
	public function zhuanpan_post()
	{
	    if(IS_POST){
			for($i=1;$i<9;$i++){
				$zp_nandu=I('zp_nandu');
				$title=I('zp_goods'.$i);
				$pic=I('lipin_img'.$i);
				$num=I('zp_goods_num'.$i);
				$jilv=I('jilv'.$i);
				$zp_content=I('zp_content');
				M('zhuanpan')->where('id='.$i)->setField([
					'zp_nandu' => $zp_nandu,
					'title' => $title,
					'pic' => $pic,
					'num' => $num,
					'jilv' => $jilv,
					'content' => $zp_content
					]);
			}
			$this->success("操作成功",U('/Admin/System/index/inc_type/zhuanpan'));
		}
	}
	
	private function initEditor()
	{
	    $this->assign("URL_upload", U('Admin/Ueditor/imageUp',array('savepath'=>'goods'))); // 图片上传目录
	    $this->assign("URL_imageUp", U('Admin/Ueditor/imageUp',array('savepath'=>'article'))); //  不知道啥图片
	    $this->assign("URL_fileUp", U('Admin/Ueditor/fileUp',array('savepath'=>'article'))); // 文件上传s
	    $this->assign("URL_scrawlUp", U('Admin/Ueditor/scrawlUp',array('savepath'=>'article')));  //  图片流
	    $this->assign("URL_getRemoteImage", U('Admin/Ueditor/getRemoteImage',array('savepath'=>'article'))); // 远程图片管理
	    $this->assign("URL_imageManager", U('Admin/Ueditor/imageManager',array('savepath'=>'article'))); // 图片管理        
	    $this->assign("URL_getMovie", U('Admin/Ueditor/getMovie',array('savepath'=>'article'))); // 视频上传
	    $this->assign("URL_Home", "");
	}
	/*
	 * 新增修改配置 
	 */
	public function handle()
	{
		$param = I('post.');
		$inc_type = $param['inc_type'];

		//unset($param['__hash__']);
		if($param['inc_type'] == 'full_reduction'){
		    
		    $Data = [];
		    foreach ($param['full_price'] as $k=>$v){
		        $Data[$k]['price'] = $v;
		        $Data[$k]['gift'] = $param['full_gift'][$k];
		    }
		    $param['full'] = json_encode($Data);
		    unset($param['full_price']);
		    unset($param['full_gift']);
		}
		unset($param['inc_type']);
		tpCache($inc_type,$param);
		$this->success("操作成功",U('System/index',array('inc_type'=>$inc_type)));
	}

    //首页活动模板列表
    public function template() {
        $template = M('template')->order("sort asc")->select();
        foreach($template as $k=>$v){
            switch($v['type']){
                case 1:
                    $template[$k]['type'] = '首页专题';
                    break;
                case 2:
                    $template[$k]['type'] = '店铺专区';
                    break;
                case 3:
                    $template[$k]['type'] = '产品专区';
                    break;
                default:
                    $template[$k]['type'] = '';
                    break;

            }
        }
        $this->assign('templateList', $template);
        $this->display();
    }
    /**
     * 添加修改编辑 首页活动模板
     */
    public  function addEditTemplate(){
        $model = D("template");
        if(IS_POST)
        {
            // $model->create();
            if($_POST['timegap']){
                $gap = explode(' - ', $_POST['timegap']);
                $_POST['start_time'] = strtotime($gap[0]);
                $_POST['end_time'] = strtotime($gap[1]);
            }

            $data = $_POST;
            $data['fenbu_id'] = json_encode($data['fenbu_id']);
            if($data['fenbu_id'] == 'null'){
                $this->error("请选择分部!!!");
            }
            unset($data['timegap']);
            if($_POST['id']) {
                $model->save($data);
            }
            else{

                $data['add_time'] = time();
                $model->add($data);

            }

            $this->success("操作成功!!!",U('Admin/System/template'));
            exit;
        }
        // 点击过来编辑时
        $id = $_GET['id'] ? $_GET['id'] : 0;
        $template = $model->find($id);
        if($template){
            $timegap = date("Y-m-d H:i:s",$template['start_time']).' - '.date("Y-m-d H:i:s",$template['end_time']);
        }else{
            $begin = date('Y-m-d 00:00',(time()-7*60*60*24));//30天前
            $end = date('Y-m-d 23:59',strtotime('+1 days'));
            $timegap = $begin.' - '.$end;
        }
        if($template['fenbu_id']){
            $template['fenbu_id'] = json_decode($template['fenbu_id'],true);
        }
        $fenbu = M('fenbu')->select();
        foreach ($fenbu as $k=>$v){

            if(in_array($v['fenbu_id'],$template['fenbu_id']) ){
                $fenbu[$k]['status'] = 1;
            }else{
                $fenbu[$k]['status'] = 2;
            }
        }
        $this->assign('fenbu_list',$fenbu);
        $this->assign('template',$template);
        $this->assign('timegap',$timegap);
        $this->display('_template');
    }


    public function deltemplate()
    {
        // 删除底部导航
        $k = M('template')->where("id = {$_GET['id']}")->delete();
        if ($k) {
            $this->success("删除成功",U('Admin/System/template'));
        } else {
            $this->error("删除失败");
        }
    }
        
       /**
        * 自定义导航
        */
    public function navigationList(){
           $model = M("Navigation");
           $navigationList = $model->order("id desc")->select(); 
		
           $this->assign('navigationList',$navigationList);
           $this->display('navigationList');          
     }
    
     /**
     * 添加修改编辑 前台导航
     */
    public  function addEditNav(){ 
            $model = D("Navigation");
            if(IS_POST)
            {
                    if ($_POST['type'] == 0){
                        $_POST['appid']='';
                    }else if($_POST['type'] == 2){
						
						$_POST['url']= $_POST['url2'];
						unset($_POST['url1']);
						unset($_POST['url2']);
					}
					else{
                        $_POST['url']= $_POST['url1'];
                        unset($_POST['url1']);
						unset($_POST['url2']);
                    }
                    $model->create();
                    if($_GET['id']) {

                        $model->save($_POST);
                    }else{
                            $model->add();

                    }
                    
                    $this->success("操作成功!!!",U('Admin/System/navigationList'));               
                    exit;
            }                    
           // 点击过来编辑时                 
           $id = $_GET['id'] ? $_GET['id'] : 0;       
           $navigation = $model->find($id);      

           $this->assign('system_nav',getsystem_nav());
           
           $this->assign('navigation',$navigation);
           $this->display('_navigation');
    }   
    
    /**
     * 删除前台 自定义 导航
     */
    public function delNav()
    {     
        // 删除导航
        M('Navigation')->where("id = {$_GET['id']}")->delete();   
        $this->success("删除成功",U('Admin/System/navigationList'));
    }
	
	public function refreshMenu(){
		$pmenu = $arr = array();
		$rs = M('system_module')->where('level>1 AND visible=1')->order('mod_id ASC')->select();
		foreach($rs as $row){
			if($row['level'] == 2){
				$pmenu[$row['mod_id']] = $row['title'];//父菜单
			}
		}

		foreach ($rs as $val){
			if($row['level']==2){
				$arr[$val['mod_id']] = $val['title'];
			}
			if($row['level']==3){
				$arr[$val['mod_id']] = $pmenu[$val['parent_id']].'/'.$val['title'];
			}
		}
		return $arr;
	}

	/**
	 * 清空系统缓存
	 */
	public function cleanCache(){

		if(IS_POST)
		{ 
		    $time = time();
		    $hour = date('H',$time);
	
		    if(false){
		        $this->error("10点到12点，16点到18点禁止清理缓存");
    			exit;
		    }else{
		  //      in_array('cache',$_POST['clear']) && delFile('./Application/Runtime/Cache');// 模板缓存
    // // 			in_array('data',$_POST['clear'])  && delFile('./Application/Runtime/Data');// 项目数据
    // 			in_array('logs',$_POST['clear'])  && delFile('./Application/Runtime/Logs');// logs日志
    // 			in_array('temp',$_POST['clear'])  && delFile('./Application/Runtime/Temp');// 临时数据
    // 			in_array('cacheAll',$_POST['clear'])  && delFile('./Application/Runtime');// 清除所有
    			//in_array('goods_thumb',$_POST['clear'])  && delFile('./Public/upload/goods/thumb'); // 删除缩略图
    			in_array('cache',$_POST['clear']) && delFile('./Application/Runtime/Cache/');// 模板缓存
    			in_array('data',$_POST['clear'])  && delFile('./Application/Runtime/Data/');// 项目数据
    			in_array('logs',$_POST['clear'])  && delFile('./Application/Runtime/Logs/');// logs日志
    			in_array('temp',$_POST['clear'])  && delFile('./Application/Runtime/Temp/');// 临时数据
    			if(in_array('cacheAll',$_POST['clear'])){
    			     delFile('./Application/Runtime/Cache/');
    			     delFile('./Application/Runtime/Data/');
    			     delFile('./Application/Runtime/Logs/');
    			     delFile('./Application/Runtime/Temp/');
    			}
             
    		    // 创建 Redis 缓存驱动实例
                // $redisDriver = new Redis();
                // 获取 Redis 实例
                // $redis = $redisDriver->clear();
                // $redisData = $redisDriver->getData();
                // dump($redisData);
    			$html_arr = glob("./Application/Runtime/Html/*.html");
    
    			foreach ($html_arr as $key => $val)
    			{
    
    				in_array('index',$_POST['clear']) && strstr($val,'Home_Index_index.html') && unlink($val); // 首页
    				in_array('goodsList',$_POST['clear']) && strstr($val,'Home_Goods_goodsList') && unlink($val); // 列表页
    				in_array('channel',$_POST['clear']) && strstr($val,'Home_Channel_index') && unlink($val);  // 频道页
    
    				in_array('articleList',$_POST['clear']) && strstr($val,'Index_Article_articleList') && unlink($val);  // 文章列表页
    				in_array('detail',$_POST['clear']) && strstr($val,'Index_Article_detail') && unlink($val);  // 文章详情
    				in_array('articleList',$_POST['clear']) && strstr($val,'Doc_Index_index_') && unlink($val);  // 文章列表页
    				in_array('detail',$_POST['clear']) && strstr($val,'Doc_Index_article_') && unlink($val);  // 文章详情
    
    				// 详情页
    				if(in_array('goodsInfo',$_POST['clear']))
    				{
    					if(strstr($val,'Home_Goods_goodsInfo') || strstr($val,'Home_Goods_ajaxComment') || strstr($val,'Home_Goods_ajax_consult'))
    						unlink($val);
    				}
    			}
    			$this->success("操作完成!!!");
    			exit;
		    }
			
		}
		$this->display();
	}
	
	
	/**
	 * 清楚演示数据
	 */
	public function cleandemo(){

		if(IS_POST)
		{
			
			//验证管理员密码是否正确
			$password=$_POST['password'];
			
			
			
			//判断是否可以清除演示数据
			if (file_exists("Public/clear_demo.txt")) {
				
					$this->error("请联系专业技术删除文件Public/clear_demo.txt文件后重试");
            }else{
				
				$table_array=array(
					'user'=>array('ty_account_log','ty_cart','ty_comment','ty_complain','ty_delivery_doc','ty_feedback','ty_goods_collect','ty_order','ty_order_comment','ty_rebate_log',
'ty_recharge','ty_remittance','ty_return_goods','ty_seller','ty_store','ty_store_apply','ty_store_collect','ty_user_address','ty_user_message',
'ty_users','ty_withdrawals'),
					'goods'=>array('ty_complain','ty_flash_sale','ty_goods','ty_goods_attr','ty_goods_collect','ty_goods_consult','ty_goods_images','ty_group_buy','ty_order_goods',
'ty_return_goods','ty_spec_goods_price','ty_spec_image','ty_goods_attr','ty_goods_attribute','ty_goods_category','ty_goods_type','ty_spec',
'ty_spec_type','ty_spec_item','ty_brand','ty_brand_type'),
					'category'=>array('ty_goods_category','ty_store_goods_class'),
					'huodong'=>array('ty_prom_goods','ty_prom_order','ty_group_buy','ty_coupon','ty_coupon_list','ty_topic','ty_pint','ty_miaosha_goods'),
					'article'=>array('ty_article','ty_article_cat'),
					'order'=>array('ty_account_log','ty_account_log_store','ty_comment','ty_complain','ty_coupon_list','ty_delivery_doc','ty_feedback','ty_order','ty_order_action',
'ty_order_comment','ty_order_extend','ty_order_goods','ty_rebate_log','ty_recharge','ty_return_goods'),
					'caiwu'=>array('ty_withdrawals'),
					'shop'=>array('ty_seller','ty_seller_group','ty_seller_log','ty_store','ty_store_apply','ty_store_bind_class','ty_store_class',
					'ty_store_collect','ty_store_decoration','ty_store_decoration_block','ty_store_distribut','ty_store_extend','ty_store_goods_class',
					'ty_store_grade','ty_store_msg','ty_store_msg_setting','ty_store_msg_tpl','ty_store_navigation','ty_store_remittance','ty_store_reopen',
					'ty_store_watermark','ty_store_waybill','ty_store_withdrawals','ty_suppliers'
					),
				);
				$tables=array();
				// foreach($_POST['clear']  as $key =>$value)
				// {
				// 	$tables=array_merge($tables,$table_array[$value]);
					
				// }
				// foreach ($tables AS $table)
				// {
				// 	$sql = "TRUNCATE   table `$table`";
				// 	M()->execute($sql);
				// }
			}
			$file = fopen("Public/clear_demo.txt","w");
            fwrite($file,"Viaweb清除数据成功".$time);
			$this->success("操作完成!!!");
			exit;
		}
		$this->display();
	}

	/**
	 * 清空静态商品页面缓存
	 */
	public function ClearGoodsHtml(){
		$goods_id = I('goods_id');
		if(unlink("./Application/Runtime/Html/Home_Goods_goodsInfo_{$goods_id}.html"))
		{
			// 删除静态文件
			$html_arr = glob("./Application/Runtime/Html/Home_Goods*.html");
			foreach ($html_arr as $key => $val)
			{
				strstr($val,"Home_Goods_ajax_consult_{$goods_id}") && unlink($val); // 商品咨询缓存
				strstr($val,"Home_Goods_ajaxComment_{$goods_id}") && unlink($val); // 商品评论缓存
			}
			$json_arr = array('status'=>1,'msg'=>'清除成功','result'=>'');
		}
		else
		{
			$json_arr = array('status'=>-1,'msg'=>'未能清除缓存','result'=>'' );
		}
		$json_str = json_encode($json_arr);
		exit($json_str);
	}
	/**
	 * 商品静态页面缓存清理
	 */
	public function ClearGoodsThumb(){
		$goods_id = I('goods_id');
		delFile("./Public/upload/goods/thumb/$goods_id"); // 删除缩略图
		$json_arr = array('status'=>1,'msg'=>'清除成功,请清除对应的静态页面','result'=>'');
		$json_str = json_encode($json_arr);
		exit($json_str);
	}
	/**
	 * 清空 文章静态页面缓存
	 */
	public function ClearAritcleHtml(){
		$article_id = I('article_id');
		unlink("./Application/Runtime/Html/Index_Article_detail_{$article_id}.html"); // 清除文章静态缓存
		unlink("./Application/Runtime/Html/Doc_Index_article_{$article_id}_api.html"); // 清除文章静态缓存
		unlink("./Application/Runtime/Html/Doc_Index_article_{$article_id}_phper.html"); // 清除文章静态缓存
		unlink("./Application/Runtime/Html/Doc_Index_article_{$article_id}_android.html"); // 清除文章静态缓存
		unlink("./Application/Runtime/Html/Doc_Index_article_{$article_id}_ios.html"); // 清除文章静态缓存
		$json_arr = array('status'=>1,'msg'=>'操作完成','result'=>'' );
		$json_str = json_encode($json_arr);
		exit($json_str);
	}
        
      //发送测试邮件
      public function send_email(){
        	$param = I('post.');
        	unset($param['inc_type']);
        	tpCache($param['inc_type'],$param);
        	if(send_email($param['test_eamil'],'后台测试','测试发送验证码:'.mt_rand(1000,9999))){
        		exit(json_encode(1));
        	}else{
        		exit(json_encode(0));
        	}
      }
	        
    /**
     *  管理员登录后 处理相关操作          
     */
     public function login_task()
     {
        // 随机清空购物车的垃圾数据 
        $time = time() - 86400*10; // 删除购物车数据  10以前的
        M("Cart")->where("add_time < $time")->delete();
       
        // 多少天后自动分销记录自动分成
        $switch = tpCache('distribut.switch');
		if($switch == 1 &&file_exists(APP_PATH.'WXAPI/Logic/DistributLogic.class.php'))
		{
			$distributLogic = new \WXAPI\Logic\DistributLogic;
			$distributLogic->auto_confirm(); // 生成分成记录
		}
		
		//更新活动购物车价格 
		$nowtime=time()-60*60*24*2;
		$goods=M('cart')->field('goods_id,prom_id,spec_key')->where('add_time>'.$nowtime)->select();

		foreach($goods as $vs){
			$new_jiage=get_goods_huodong($vs['goods_id'],$vs['spec_key']);
				M('cart')->where('goods_id='.$vs['goods_id'].' and `spec_key` = "'.$vs['spec_key'].'"')->setField([
				'spec_key_name'=>$new_jiage["key_name"],
				'goods_price'=>sanwei($new_jiage["price"]),
				'member_goods_price'=>sanwei($new_jiage["price"]),
				'prom_msg'=>$new_jiage["prom_msg"],
				'prom_id'=>$new_jiage["prom_id"]
			]);
		}
     }
     
     function ajax_get_action()
     {
     	$control = I('controller');
     	$advContrl = get_class_methods("Admin\\Controller\\".$control);
     	//dump($advContrl);
     	$baseContrl = get_class_methods('Admin\Controller\BaseController');
     	$diffArray  = array_diff($advContrl,$baseContrl);
     	$html = '';
     	foreach ($diffArray as $val){
     		$html .= "<option value='".$val."'>".$val."</option>";
     	}
     	exit($html);
     }
     
     function right_list(){
     	$group = groupMenu();
     	$right_list = M('system_menu')->select();
     	$this->assign('right_list',$right_list);
     	$this->assign('group',$group);
     	$this->display();
     }
      
     public function edit_right(){
     	if(IS_POST){
     		$data = I('post.');
     		$data['right'] = implode(',',$data['right']);
     		if(!empty($data['id'])){
     			M('system_menu')->where(array('id'=>$data['id']))->save($data);
     		}else{
     			if(M('system_menu')->where(array('name'=>$data['name']))->count()>0){
     				$this->error('该权限名称已添加，请检查',U('System/right_list'));
     			}
     			unset($data['id']);
     			M('system_menu')->add($data);
     		}
     		$this->success('操作成功',U('System/right_list'));
     		exit;
     	}
     	$id = I('id');
     	if($id){
     		$info = M('system_menu')->where(array('id'=>$id))->find();
     		$info['right'] = explode(',', $info['right']);
     		$this->assign('info',$info);
     	}
    	// $group = array('system'=>'系统设置','content'=>'内容管理','goods'=>'商品中心','member'=>'会员中心',
    	// 		'order'=>'订单中心','marketing'=>'营销推广','tools'=>'插件工具','count'=>'统计报表',
    	// 		'weixin'=>'微信管理','store'=>'店铺管理','jifen'=>'积分商城','pintuan'=>'拼团管理','finance'=>'财务统计'
    	// );
    	$group = groupMenu();
     	$planPath = APP_PATH.'Admin/Controller';
     	$planList = array();
     	$dirRes   = opendir($planPath);
     	while($dir = readdir($dirRes))
     	{
     		if(!in_array($dir,array('.','..','.svn')))
     		{
     			$planList[] = basename($dir,'.class.php');
     		}
     	}
     	$this->assign('planList',$planList);
     	$this->assign('group',$group);
     	$this->display();
     }
      
     public function right_del(){
     	$id = I('del_id');
     	if(is_array($id)){
     		$id = implode(',', $id);
     	}
     	if(!empty($id)){
     		$r = M('system_menu')->where("id in ($id)")->delete();
     		if($r){
     			respose(1);
     		}else{
     			respose('删除失败');
     		}
     	}else{
     		respose('参数有误');
     	}
     }
     
     //会员中心导航
     public function user_nav() {
         $nav = M('navigation_user')->order("sort asc")->select();
		 $this->assign('navigationList', $nav);
		 $this->display();
     }
     
     /**
     * 添加修改编辑 会员中心导航
     */
    public  function addEditNavUser(){       
        // dump(get_usercenter_nav());
            $model = D("Navigation_user");            
            if(IS_POST)
            {
                    
                    if ($_POST['type'] == 0){
                        $_POST['appid']='';
                    }else{
                        $_POST['url']= $_POST['url1'];
                        unset($_POST['url1']);
                    }
					$model->create();
                    if($_GET['id']){

                        $model->save();
                    }else{
					
                        $model->add();
                    }
                    $this->success("操作成功!!!",U('Admin/System/user_nav'));               
                    exit;
            }                    
           // 点击过来编辑时                 
           $id = $_GET['id'] ? $_GET['id'] : 0;       
           $navigation = $model->find($id);
            // dump($navigation);
           // 系统菜单         
           $this->assign('system_nav',get_usercenter_nav());
           
           $this->assign('navigation',$navigation);
           $this->display('_navigation');
    }
    
    public function delNavUser()
    {     
        // 删除导航
        $k = M('navigation_user')->where("id = {$_GET['id']}")->delete();
		if ($k) {
			$this->success("删除成功",U('Admin/System/user_nav'));
		} else {
				$this->error("删除失败");
		}
    }
	
     //底部导航
     public function tab() {
         $nav = M('navigation_tab')->order("sort asc")->select();
		$this->assign('navigationList', $nav);
		$this->display();
     }
     
     /**
     * 添加修改编辑 底部导航
     */
    public  function addEditTabUser(){                        
            $model = D("Navigation_tab");            
            if(IS_POST)
            {
				
                    if ($_POST['type'] == 0){
                        $_POST['appid']='';
                    }else if($_POST['type'] == 2){
						
						$_POST['url']= $_POST['url2'];
						unset($_POST['url1']);
						unset($_POST['url2']);
					}
					else{
                        $_POST['url']= $_POST['url1'];
                        unset($_POST['url1']);
						unset($_POST['url2']);
                    }			
                    $model->create();
                    if($_GET['id']) {
                        $model->save();
                    }
                    else{
                            $model->add();

                     }
                    
                    $this->success("操作成功!!!",U('Admin/System/tab'));               
                    exit;
            }                    
           // 点击过来编辑时                 
           $id = $_GET['id'] ? $_GET['id'] : 0;       
           $navigation = $model->find($id);      

           $this->assign('system_nav',getsystem_nav());
           
           $this->assign('navigation',$navigation);
           $this->display('_navigation');
    }
    
    public function delTabUser()
    {     
        // 删除底部导航
        $k = M('navigation_tab')->where("id = {$_GET['id']}")->delete();
		if ($k) {
			$this->success("删除成功",U('Admin/System/tab'));
		} else {
				$this->error("删除失败");
		}
    }
}